package com.topscore.utillibrary.util;

import android.os.CountDownTimer;

/**
 * Created by Li Guoxi on 2016/9/21.
 */

public class CountDownUtil extends CountDownTimer {

    private OnCountDownListener mOnCountDownListener;

    public CountDownUtil(int totalSeconds) {
        super(totalSeconds * 1000, 1000);
    }

    public CountDownUtil(int totalSeconds, OnCountDownListener listener) {
        this(totalSeconds);
        this.mOnCountDownListener = listener;
    }

    public CountDownUtil setOnCountDownListener(OnCountDownListener listener) {
        this.mOnCountDownListener = listener;
        return this;
    }

    @Override
    public void onTick(long l) {
        mOnCountDownListener.onCount((int) (l / 1000));
    }

    @Override
    public void onFinish() {
        mOnCountDownListener.onCountDownComplete();
    }

    public interface OnCountDownListener {
        void onCount(int seconds);

        void onCountDownComplete();
    }
}
